package cn.gene.timeyan.article.webapi.controller;


import cn.gene.timeyan.article.service.ReplyService;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.article.dto.ReplyDTO;
import cn.gene.timeyan.pojo.article.vo.ReplyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 鏂囩珷璇勮?鐨勫洖澶 前端控制器
 * </p>
 *
 * @author LWG
 * @since 2022-07-25
 */
@RestController
@RequestMapping("/reply")
@Api(tags = "reply模块")
public class ReplyController {

    @Autowired
    private ReplyService replyService;
    @PutMapping("/display/{id}")
    @ApiOperation("显示回复")
    public JsonResult<Void> display(@PathVariable("id") Long id){
        replyService.display(id);
        return JsonResult.ok();
    }
    @PutMapping("/hide/{id}")
    @ApiOperation("隐藏回复")
    public JsonResult<Void> hide(@PathVariable("id") Long id){
        replyService.hide(id);
        return JsonResult.ok();
    }
    /**
     * 增加回复
     * @param replyDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加回复")
    public JsonResult<Void> addNew(ReplyDTO replyDTO){
        replyService.addNew(replyDTO);
        return JsonResult.ok();
    }

    /**
     * 显示某一条评论下的回复,初始返回20条,按照时间降序
     * @param commentId
     * @param model 降序 desc 升序 asc
     * @param page
     * @return
     */
    @GetMapping("/{commentId}/{model}/{page}")
    @ApiOperation("获取回复列表")
    public JsonResult<List<ReplyVO>> list(@PathVariable() Long commentId, @PathVariable String model, @PathVariable Integer page){
        List<ReplyVO> replyVOS=replyService.listByCommentId(commentId,model,page);
        System.out.println(replyVOS);
        return JsonResult.ok(replyVOS);
    }
}

